package com.base.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.base.po.voip.ShopText;
import com.base.po.voip.Shopinfoes;
import com.base.service.ShopTextService;
import com.base.service.ShopinfoService;

/**
 * 滚动文字信息服务端
 * 
 * @author f
 * 
 */
@Controller
@RequestMapping("/admin")
public class index_Roll {

	@Autowired
	private ShopTextService shopTextService; // 商城滚动
	@Autowired
	private ShopinfoService shopinfoService; // 发现滚动

	// 滚动文字首页
	@RequestMapping("/rollIndex")
	public ModelAndView rollIndex(HttpServletRequest request) throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
		Map<String, Object> map = new HashMap<>(); // 返回数据对象
		map.put("shopTexts", shopTextService.selectByAll(new ShopText(true, 2, userid))); // 商城文字
		map.put("shopinfoes", shopinfoService.selectByAll(new Shopinfoes(true, 2, userid))); // 发现文字
		return new ModelAndView("jsp/index_Roll", map);
	}

	// 跳转添加商城滚动
	@RequestMapping("/addMallroll")
	public String addMallroll() throws Exception {
		return "jsp/add_Mallroll";
	}

	// 跳转添加发现滚动
	@RequestMapping("/addFindroll")
	public String addFindroll() throws Exception {
		return "jsp/add_Findroll";
	}

	// 跳转修改商城滚动文字
	@RequestMapping("/updateMallroll")
	public ModelAndView updateMallroll(String id) throws Exception {
		return new ModelAndView("jsp/update_Mallroll", "shopText", shopTextService.selectByPrimaryKey(id));
	}

	// 跳转修改发现滚动文字
	@RequestMapping("/updateFindroll")
	public ModelAndView updateFindroll(String id) throws Exception {
		return new ModelAndView("jsp/update_Findroll", "shopinfoes", shopinfoService.selectByPrimaryKey(id));
	}
}
